<template>
  <!-- 量表结果详细 -->
  <section v-if="tableData">
    <div class="form-tool">
      <!-- 名称：{{dataItem.scaleName}} -->
      <div>评测日期：{{tableData.gmtCreate}} </div>
      <div>
        <el-button @click="onprint">打印</el-button>
      </div>
    </div>
    <br>
    <div style="display: flex;" class="error-color">
      <div style="flex-shrink: 0;padding-right:20px;">
        <h3 style="margin:0;" v-if="tableData.scaleRuleType==0"> 评测结果：{{tableData.score}}分</h3>
        <h3 style="margin:0;" v-else> 评测结果：</h3>
      </div>
      <div style="flex-grow: 1;">
        <h3 style="margin:0;" v-for="(item,index) in tableData.scaleScoreRules" :key="index">{{item.scoreTypeName}}&nbsp;{{item.getScore}}&nbsp;{{item.scoreTypeDesc}};</h3>
      </div>
    </div>
    <br>
    <div v-for="(item,index) in tableData.pageInfo.list" :key="index" class="item-box">
      <div class="title">{{index+1}}：{{item.itemName}}</div>
      <div class="daan">{{item.checkName}}</div>
    </div>
    <iframe ref="iframe1" frameborder="0" height="0px" width="0px" src="/print/lb.html"></iframe>
  </section>
</template>
<script> 
export default {
  props: ["patientId", "dataItem", "patientInfo"],
  data() {
    return {
      tableData: null
    };
  },
  mounted() {
    const th = this;
    th.getData();
  },
  methods: {
    getData() {
      const th = this;
      let j = {
        scaleId: th.dataItem.scaleId,
        patientId: th.patientId,
        pageNum: 1,
        pageSize: 200
      };
      th.$api.getScaleAnswerRecordDetailScaleIdAndPatientId(j).then(res => {
        if (res.executed) {
          let d = res.dataBody;
          if (d.gmtCreate) {
            d.gmtCreate = th.$utils.FormatTime("yyyy-MM-dd", d.gmtCreate);
          }
          th.tableData = d;
        }
      });
    },
    onprint() {
      const th = this;
      let json = {
        hospital: {
          name: th.adminUser.hospitalName,
          logo: th.adminUser.printLogo,
          address: th.adminUser.hospitalAddress
        },
        detail: th.tableData,
        data: th.dataItem,
        patient: th.patientInfo
      };
      th.$refs["iframe1"].contentWindow.postMessage(
        json,
        `${window.location.origin}/print/lb.html`
      );
    }
  }
};
</script>
<style lang="scss" scoped>
.item-box {
  padding: 15px;
  .title {
    padding-bottom: 10px;
    font-weight: bold;
  }
}
</style>